/*
 * @Company: TWL
 * @Author: xue jian
 * @Email: xuejian@kanzhun.com
 * @Date: 2019-11-18 22:21:21
 */
#include <Eigen/Dense>
#include <vector>
#include <iostream>
#include <memory>
#include <cstdlib>
#include <time.h>
#include <sstream>
#include "MatrixRand.h"
using namespace Eigen;
int main() {
	srand(time(NULL));
	std::vector<float> haha;
	for (int i(0); i<240000; ++i) {
		haha.push_back(rand()*0.1);
	}
	std::string test;
	for (auto& s:haha) {
		test+=std::to_string(s);
		test+="\t";
	}
	std::stringstream ss_test(test);
	std::vector<float> hehe;
	std::string tmp;
	double start_t = Time_tag();
	MatrixXf mat1(MatrixXf::Zero(2400, 100));
	int row_index(0);
	int col_index(0);
	while (getline(ss_test, tmp, '\t')) {
		//hehe.push_back(std::stof(tmp));
		mat1(row_index, col_index) = std::stof(tmp);
		col_index++;
		if (col_index>=100) {
			row_index++;
			col_index = 0;
		}
	}
	std::cout<<"The gangt takes "<<Time_tag()-start_t<<std::endl;
	std::string test2(sizeof(float)*haha.size(), '0');
	
	std::memcpy(&test2[0], &haha[0], test2.size());
	
	std::vector<float> haha2(haha.size());
	
    // MatrixXf mat2(MatrixXf::Zero(2400, 100));
	start_t = Time_tag();
	std::memcpy(&haha2.at(0), &test2[0], test2.size());
	std::vector<double> double_haha(haha2.begin(), haha2.end());
	MatrixXf mat2(Map<MatrixXf>(&haha2[0], 2400, 100));
	std::cout<<"the memcpy takes "<<Time_tag()-start_t<<std::endl;
	float check(0);
	// for (size_t i(0); i<haha.size(); ++i) {
	// 	check+=abs(haha.at(i)-double_haha.at(i));
	// }
	std::cout<<"the memcpy check is "<<check<<std::endl;

	check = 0;
	//for (size_t i(0); i<haha.size(); ++i) {
	//	check+=abs(haha.at(i) - hehe.at(i));
	//}
	std::cout<<"the gangt check is "<<check<<std::endl;

}